class_name GameInputEvents

static var direction: Vector2
static var mul_direction: Vector2


static func movement_input() -> Vector2:
	direction = Vector2.ZERO
	
	var joy_dir: Vector2 = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
	joy_dir = joy_dir.normalized()
	print("joy方向: ", joy_dir)
	mul_direction = joy_dir
	direction = get_cardinal_direction(joy_dir)
	print("dir方向: ", direction)
	return direction


static func is_movement_input() -> bool:
	return direction != Vector2.ZERO


static func is_interact_input() -> bool:
		return Input.is_action_pressed("interact")

# 定义一个函数来转换摇杆输入为四个主要方向
static func get_cardinal_direction(input_vector: Vector2) -> Vector2:
	# 首先检查输入向量是否接近于零
	if input_vector.length() < 0.1:
		return Vector2.ZERO  # 返回零向量，表示没有主要方向

	# 计算输入向量的角度
	var angle = input_vector.angle()

	# 将角度转换为弧度，并进行四舍五入以确定主要方向
	if angle >= -PI / 4 and angle < PI / 4:
		return Vector2.RIGHT
	elif angle >= PI / 4 and angle < 3 * PI / 4:
		return Vector2.DOWN
	elif angle >= 3 * PI / 4 or angle < -3 * PI / 4:
		return Vector2.LEFT
	else:
		return Vector2.UP
